function checkPassword() {
    // let var
    let password = document.getElementById("password").value;
    let rePassword = document.getElementById("rePassword").value;
    if (password != rePassword) {
        // innerText 文本域
        // innerHTML html
        document.getElementById("passwordTip").innerHTML = "两次密码输入不一致，请重新输入!";
        document.getElementById("passwordTip").style.color = "red";
        // document.getElementById("rePassword").focus();
    } else {
        document.getElementById("passwordTip").innerHTML = "密码输入一致!";
        document.getElementById("passwordTip").style.color = "green";
    }
}

function register() {
    //js数据类型
    //数字，字符串，数组，对象，布尔

    let data = {
        username: $("#username").val(),
        password: $("#password").val(),
        phone: $("#phone").val(),
        sex: $("input[name='sex']:checked").val(),
        birthday: $("#birthday").val(),
        code: $("#code").val(),
        hobby: JSON.stringify(aihao()),
        introduce: $("#introduce").val()
    };
    console.log(data);
    $.ajax({
        url: '/userRegister',//访问后台servlet里面的地址@WebServlet("/userRegister")
        data: data,//页面传递到后台的值
        type: 'post',//对应servlet里面方法的名字
        dataType: 'json',//返回一个json对象
        success: function (data) {//后台返回给页面的值
            console.log(data);
            if (data == 1) {
                // window.location.href = "/back/login.html";
                window.open("/back/login.html", "_blank");
            } else if (data == 4) {
                alert("你输入的用户名已经存在");
            } else {
                alert("注册失败");
            }
        }
    })
}


function aihao() {
    let hb = [];
    $("input:checkbox[name='hobby']").each(function () {
       console.log();
        if ($(this).prop("checked")) {
            hb.push($(this).val());
        }
    })

    return hb;
}

// function aa() {
//     let reg=/3/gim;
//     let bb="fa23 fFDSFA423sfa43yhg";
//     let regg=/fa\b/;
//     let aa=new RegExp(reg);
//     let username=document.getElementById("username").value;
//     if(aa.test(username)){
//
//     }else {
//        let tishi=document.getElementById("tishi");
//        tishi.style.display="block";
//     }
// }